package sk.uniza.fri.cerviix.server.game;

import sk.uniza.fri.cerviix.server.network.Client;

public class Player
{
	private static int lastId = 0;
	
	private static int generateId()
	{
		lastId++;
		
		return lastId;
	}

	private Client client;
	
	private int id;
	private String name;
	
	private Worm worm;
	
	private Score score;
	
	public Player(Client client, String name)
	{
		this.client = client;
		
		this.id = generateId();
		this.name = name;
		
		this.score = new Score();
	}
	
	public Client getClient()
	{
		return client;
	}
	
	public void removeClient()
	{
		client = null;
	}
	
	public int getId()
	{
		return id;
	}
	
	public String getName()
	{
		return name;
	}
	
	public Score getScore()
	{
		return score;
	}
	
	public boolean hasWorm()
	{
		return (worm == null) ? false : true;
	}
	
	public void addWorm(Worm worm)
	{
		this.worm = worm;
	}
	
	public Worm getWorm()
	{
		return worm;
	}
	
	public static class Score
	{
		private int score;
		
		public void add()
		{
			score += 10;
		}
		
		public void sub()
		{
			if (score > 0)
			{
				score -= 1;
			}
		}
		
		public int get()
		{
			return score;
		}
		
		public String toString()
		{
			return Integer.toString(score);
		}
	}
}
